import 'dart:async';

class TimerClass {
  Timer? _timer;
  late int _count;

  void start(int time, Function(int) callback) {
    _count = time;
    _timer = Timer.periodic(Duration(seconds: 1), (Timer t) {
      _count--;
      callback(_count);
      // print('Count: $_count');
      if (_count == 0) {
        t.cancel(); // 取消定时器
      }
    });
  }

  void stop() {
    if (_timer != null) {
      _timer!.cancel(); // 取消定时器
    }
  }
}
